597A - Divisibility - CodeForces Solution


math *1600

Please click on ads to support us..

Python Code:

k, a, b = map(int, input().split())

ans = 0

r = a % k

if r == 0 :
    start_ind = a
else : 
    start_ind = a + k - r

ans = (b - start_ind) // k

print(ans + 1)

C++ Code:

#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <unordered_set>
#include <cassert>
#include <unordered_map>
#include <math.h>
#include <iomanip>

typedef long long ll;

void solve() {
    ll k, a, b;
    std::cin >> k >> a >> b;

    ll first_num = a / k * k;
    if (first_num < a) {
        first_num += k;
    }

    ll last_num = b / k * k;
    if (last_num > b) {
        last_num -= k;
    }
    ll i = first_num / k;
    ll j = last_num / k;

    ll answer = j - i + 1;
    std::cout << answer << std::endl;
}

int main() {
    solve();
}  


Comments

Submit
0 Comments
More Questions

1674E - Breaking the Wall
1282A - Temporarily unavailable
1366C - Palindromic Paths
336A - Vasily the Bear and Triangle
926A - 2-3-numbers
276D - Little Girl and Maximum XOR
1253C - Sweets Eating
1047A - Little C Loves 3 I
758D - Ability To Convert
733A - Grasshopper And the String
216A - Tiling with Hexagons
1351B - Square
1225A - Forgetting Things
1717A - Madoka and Strange Thoughts
1717B - Madoka and Underground Competitions
61B - Hard Work
959B - Mahmoud and Ehab and the message
802G - Fake News (easy)
1717C - Madoka and Formal Statement
420A - Start Up
1031A - Golden Plate
1559C - Mocha and Hiking
427B - Prison Transfer
330A - Cakeminator
426A - Sereja and Mugs
363A - Soroban
1585C - Minimize Distance
1506E - Restoring the Permutation
1539A - Contest Start
363D - Renting Bikes